
Date.prototype.format || (Date.prototype.format = function(format) {
	var o = {
	"M+" : this.getMonth()+1, //month
	"d+" : this.getDate(), //day
	"h+" : this.getHours(), //hour
	"m+" : this.getMinutes(), //minute
	"s+" : this.getSeconds(), //second
	"q+" : Math.floor((this.getMonth()+3)/3), //quarter
	"S" : this.getMilliseconds() //millisecond
	};
	if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
	(this.getFullYear()+"").substr(4- RegExp.$1.length));
	for(var k in o)if(new RegExp("("+ k +")").test(format))
	format = format.replace(RegExp.$1,
	RegExp.$1.length==1? o[k] :
	("00"+ o[k]).substr((""+ o[k]).length));
	return format;
});
/**
 * com.cysyz.datetime package
 *
 * This package contains utility functions for working with dates and times.
 *
 * @author <a href="mailto:fzammetti@omnytex.com.cysyz">Frank W. ZAmmetti</a>
 */
if (typeof com.cysyz == 'undefined') {
  com.cysyz = function() { };
};


com.cysyz.datetime = function() { };


/**
 * This function will return the number of days in a given month and year,
 * taking leap years into account.
 *
 * @param  inMonth The month, where January = 1 and December = 12.
 * @param  inYear  The year to check the month in.
 * @return         The number of days in the specified month and year.
 */
com.cysyz.datetime.getNumberDaysInMonth = function(inMonth, inYear) {

  inMonth = inMonth - 1;
  var leap_year = this.isLeapYear(inYear);
  if (leap_year) {
    leap_year = 1;
  } else {
    leap_year = 0;
  }
  if (inMonth == 3 || inMonth == 5 || inMonth == 8 || inMonth == 10) {
    return 30;
  } else if (inMonth == 1) {
    return 28 + leap_year;
  } else {
    return 31;
  }

}; // End getNumberDaysInMonth().


/**
 * This function will determine if a given year is a leap year.
 *
 * @param  inYear The year to check.
 * @return        True if inYear is a leap year, false if not.
 */
com.cysyz.datetime.isLeapYear = function(inYear) {

  if ((inYear % 4 == 0 && !(inYear % 100 == 0)) || inYear % 400 == 0) {
    return true;
  } else {
    return false;
  }

}; // End isLeapYear().

/**
 * 取得当前日期之前后之后的某一个日期 
 * @param {number} offset 偏移量，单位为日
 * @param {string} format 日期格式
 * @return 当前日期之前后之后的某一个日期
 */
com.cysyz.datetime.getDateOffset = function(offset, format) {
	if (offset == null) {
		offset = 0;
	} 
	var date = new Date();
	date.setTime(date.getTime() + offset * 24 * 3600000);
	return format == null && date.format("yyyy-MM-dd") || date.format(format);	

}; // End getDateOffset().
